package com.hanrui.android.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.vipulasri.timelineview.TimelineView;
import com.hanrui.android.R;
import com.hanrui.android.model.VoteDetailBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/2/9.
 */

public class VoteDetailLcAdapter extends RecyclerView.Adapter<VoteDetailLcAdapter.LcViewHolder> {
    private List<VoteDetailBean.ResultListBean> mFeedList;
    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public void setNewData(List<VoteDetailBean.ResultListBean> mFeedList){
        this.mFeedList = mFeedList;
        notifyDataSetChanged();
    }


    @Override
    public int getItemViewType(int position) {
        return TimelineView.getTimeLineViewType(position,getItemCount());
    }

    @Override
    public LcViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        mLayoutInflater = LayoutInflater.from(mContext);
        View view ;
        view = mLayoutInflater.inflate(R.layout.item_votedetail,parent,false);
        return new LcViewHolder(view,viewType);
    }

    @Override
    public void onBindViewHolder(LcViewHolder holder, int position) {
        VoteDetailBean.ResultListBean item = mFeedList.get(position);
        holder.lcContent.setText(item.getREMARKS());
        holder.lcTime.setText(item.getNAME());

        holder.typelogo.setImageResource(R.mipmap.pass);
        holder.mTimelineView.setMarker(ContextCompat.getDrawable(mContext,R.drawable.gouxuan));

    }

    @Override
    public int getItemCount() {
        return mFeedList!=null?mFeedList.size():0;
    }


    class LcViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.lc_content)
        TextView lcContent;
        @BindView(R.id.lc_time)
        TextView lcTime;
        @BindView(R.id.time_marker)
        TimelineView mTimelineView;
        @BindView(R.id.typelogo)
        ImageView typelogo;

        public LcViewHolder(View itemView, int viewType) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            mTimelineView.initLine(viewType);
        }
    }
}